package com.jiugang.cardump.util;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author lxmac
 * @DateTime 2021/7/1 下午1:57
 * @Des 分页工具类
 **/
@Slf4j
public class PageUtil {

     /*
      * @Author luoxin
      * @Description //返回分页相关参数方法
      * @Date 下午1:57 2021/7/1
      * @Param  page:当前页  size:每页展示条数 total:总条数
      * @return
      */
    public static  Map<String,Integer> getPageInfo(Integer page,Integer size,Integer total){

        Map<String,Integer> pageInfoMap = new HashMap<>();
        pageInfoMap.put("page",page);
        pageInfoMap.put("size",size);
        pageInfoMap.put("total",total);
        log.info("--------totalPage: " + total);
        pageInfoMap.put("totalPage",(total % size != 0 ? total /size + 1 : total / size));

        return pageInfoMap;
    }

     /*
      * @Author luoxin
      * @Description //
      * @Date 下午4:04 2021/7/1
      * @Param
      * @return
      */
    public static Integer getPageIndex(Integer page,Integer size){

        return size * (page - 1) ;
    }


    /*
     * @Author wuweinan
     * @Description //计算总页数
     * @Date 下午4:04 2021/7/1
     * @Param totalCount:查询出的结果条数,size:每页条数
     * @return
     */
    public static Integer getTotalPage(Integer totalCount,Integer size){
        Double doubleCount = (double)totalCount/size;
        double ceil = Math.ceil(doubleCount);
        int totolPage = (int)ceil;
        return totolPage;
    }

}
